package com.tong.embeddedvr.service.impl;

import com.tong.embeddedvr.Mapper.StatisticMapper;
import com.tong.embeddedvr.entity.StatisticEntity;
import com.tong.embeddedvr.service.StatisticService;
import com.tong.embeddedvr.utils.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StatisticServiceImpl implements StatisticService {

    @Autowired
    private StatisticMapper statisticMapper;

    @Override
    public String getAll() {
        String res;
        try{
            StatisticEntity[] statisticBeans = statisticMapper.getAll();
            res = CommonUtil.ajaxReturn(statisticBeans);
        }catch (Exception exception){
            exception.printStackTrace();
            res = CommonUtil.ajaxReturn(400,"数据请求失败,请确认是否具有权限");
        }
        return res;
    }

    @Override
    public String addCount(String name) {
        String res;
        try{
            statisticMapper.increaseCount(name);
            res = CommonUtil.ajaxReturn("返回成功");
        }catch(Exception e){
            e.printStackTrace();
            res = CommonUtil.ajaxReturn(400,"统计数据添加失败");
        }
        return res;
    }
}
